//
//  RainScrollView.m
//  UI06_UIScrollView
//
//  Created by Bodi on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RainScrollView.h"
@interface RainScrollView ()<UIScrollViewDelegate>
@end

@implementation RainScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setProtertys];
    }
    return self;

}
- (void)setProtertys{
/**
 * 重点
 * frame设置的是scrollView的可视范围,contentSize设置的是scrollview的滚动范围
 * 当contentSize的width大于frame的width时, 水平方向的可以滚动, 小于等于时水平方向不可以滚动
 * 当contentSize的heifht大于frame的height时, 垂直方向可以滚动,小于等于时垂直方向不可以滚动
 
 
 */
    self.contentSize = CGSizeMake(1000, 500);
    /**不显示滑动条*/
    self.showsVerticalScrollIndicator = NO;/** 垂直方向*/
    self.showsHorizontalScrollIndicator = NO;/** 水平方向*/
    /** 设置分页效果 */
    self.pagingEnabled = YES;
    /** 回弹效果 , 默认开启*/
//    self.bounces = NO;
    
    
    
    /** 设置放大缩小的比例因子 */
//    self.maximumZoomScale = 2;
//    self.minimumZoomScale = 0.5;
}
/** 添加图片 */
- (void)addPictures:(NSArray <UIImage *> *)picutureArray{
    /** 确定滚动范围 */
    self.contentSize = CGSizeMake(CGRectGetWidth(self.bounds)* picutureArray.count, 0);

    for (int i = 0; i < picutureArray.count; i++) {
        /** 创建小的scrollView. */
        UIScrollView  *scroll= [[UIScrollView alloc]initWithFrame:CGRectMake(i * CGRectGetWidth(self.bounds), 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
        scroll.delegate = self;
        scroll.maximumZoomScale = 2;
        scroll.minimumZoomScale = 0.5;
        /** 创建UIImageView */
        UIImageView *imageView = [[UIImageView alloc]initWithImage:picutureArray[i]];
        imageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
        [scroll addSubview:imageView];
        [self addSubview:scroll];
        
        [imageView release];
        [scroll release];
    }



}
/*放大缩小的协议方法*/
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

    return scrollView.subviews.firstObject;

}

@end
